﻿@{
    Layout = null;
}
@model MIMS.Entity.Model.PSS_PurchasePlan

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>PurchasePlanDetail</title>
    @*Easyui需要引入的文件*@
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.5/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
    <link href="~/Content/jquery-easyui-1.4.5/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Content/jquery-easyui-1.4.5/themes/icon.css" rel="stylesheet" />
    <link rel="shortcut icon" href="/favicon.ico" />
    <link rel="bookmark" href="/favicon.ico" />
    <script src="~/Content/My97DatePicker/WdatePicker.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    @*本地css和js引入*@
    <link href="~/Content/Site.css" rel="stylesheet" />
    <script src="~/Content/Site.js"></script>
    <script>
        $(function () {
            var status = @Model.PurchaseStatus;
            var msg = "";
            if(status==0)
                msg = "未采购";
            else if(status == 1)
                msg = "采购中";
            else
                msg = "已采购";
            $('#status').text(msg);

            if(status != 0)
            {
                $('#body').layout('remove', 'west');
            }
            else
            {
                InitPhaDialoggrid();
            }
            InitGrid();
            InitDialog();
            $('#ok').click(function () {
                $('#errdiv').removeClass('dis');
                $('#form').submit();
            });
            $('#cancel').click(function () {
                $('#dd').dialog('close');
            });
        });


        //实现对DataGird控件的绑定操作
        function InitGrid() {
            $('#grid').datagrid({
                url: '../PSS_PurchasePlanDetail/LoadList',
                singleSelect: true,
                fit: true,
                nowrap: true,//单行显示
                autoRowHeight: false,
                striped: false,     //斑马纹
                collapsible: true,      //可折叠
                pagination: true,
                pageSize: 20,
                fitColumns: true,       //自适应列宽
                rownumbers: true,
                sortName: 'ID',    //根据某个字段给easyUI排序
                sortOrder: 'asc',
                remoteSort: true,
                loadMsg: '加载中，请等待',
                queryParams: ({
                    query:'@Model.PurchaseNo'
                }),  //异步查询的参数
                columns: [[
                     { title: '编号', field: 'ID', hidden: true },
                     { title: '药品编号', field: 'PhaCode', hidden: true },
                     { title: '采购单号', field: 'PurchaseNo', hidden: true },
                     { title: '药品名称', field: 'PhaName', sortable: true},
                     { title: '规格', field: 'Spec', sortable: true },
                     { title: '单位', field: 'Unit',  sortable: true, align: 'center' },
                     { title: '拼音代码', field: 'PinyinCode',sortable: true, align: 'center' },
                     { title: '产地', field: 'OrginName', sortable: true, align: 'center' },
                     { title: '采购价格', field: 'InWarehousePrice', sortable: true, align: 'center' },
                     { title: '采购数量', field: 'PurchaseNum', sortable: true, align: 'center' },
                     { title: '采购金额', field: 'InWarehouseSum', sortable: true, align: 'center' },
                     { title: '库存', field: 'Stock',  sortable: true, align: 'center' },
                     { title: '供货单位', field: 'CompanyName',sortable: true },
                ]],
                onDblClickRow: function (rowIndex, rowData) {

                },
                onClickRow: function (index, row) {
                    $('#del_id').val(row['ID']);
                    console.log(row['PhaCode']);
                }

            })
            var p = $('#grid').datagrid('getPager');
            $(p).pagination({
                pageSize: 20,
                pageList: [10, 12, 20, 40, 60, 100, 200],
                beforePageText: '第',
                afterPageText: '页   共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
                buttons: [{
                    iconCls:'icon-remove',
                    handler:function(){
                        if(@Model.PurchaseStatus == 0){
                            getAjax("../PSS_PurchasePlanDetail/Del", { id: $('#del_id').val() }, function (data) {
                                if ($('#del_id').val() == null || $('#del_id').val() == "")
                                    return false;
                                if (data) {
                                    $.messager.alert('提示', '删除药品成功!');
                                    $('#dd').dialog('close');
                                    $("#grid").datagrid("reload");
                                    return true;
                                }
                                else {
                                    $.messager.alert('提示', '操作失败!');
                                    return false;
                                }
                            });
                        }
                        else
                            $.messager.alert('提示', '当前采购状态下无法编辑操作失败!');

                    }
                }]
            });
        };


        //药品选择器
        function InitPhaDialoggrid() {
            $('#phagrid').datagrid({
                url: '../PHA_Accounts/LoadList',
                fit: true,
                nowrap: true,//单行显示
                autoRowHeight: false,
                singleSelect: true,
                striped: false,     //斑马纹
                collapsible: true,      //可折叠
                pagination: true,
                pageSize: 20,
                fitColumns: true,       //自适应列宽
                rownumbers: true,
                sortName: 'PhaCode',    //根据某个字段给easyUI排序
                sortOrder: 'asc',
                remoteSort: true,
                loadMsg: '加载中，请等待',
                queryParams: ({
                    pinyin: $('#phagrid_dir').val()
                }),  //异步查询的参数
                columns: [[
                     { title: '编号', field: 'PhaCode', hidden: true },
                     { title: '药名', field: 'PhaName', sortable: true },
                     { title: '规格', field: 'Spec', sortable: true },
                     { title: '单位', field: 'Unit', sortable: true, },
                     { title: '产地', field: 'OrginName' }
                ]],
                toolbar: '#phagrid_tb',
                onDblClickRow: function (rowIndex, rowData) {
                    $('#errdiv').attr('class', 'dis');
                    $('#PurchaseNum').val("");
                    getAjax("../PHA_Accounts/LoadForm",
                        { phaCode: rowData['PhaCode'], orginID: rowData['OrginID'] }, function (data) {
                            var data = eval("(" + data + ")");
                            SetWebControls(data);
                        });
                    $('#dd').dialog('open');
                }
            })
            var p = $('#phagrid').datagrid('getPager');
            $(p).pagination({
                pageSize: 20,
                pageList: [10, 12, 20, 40, 60, 100, 200],
                beforePageText: '第',
                afterPageText: '页   共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            });
        };

        //初始化对话框
        function InitDialog() {
            $('#dd').dialog({
                title: '添加药品',
                width: 700,
                height: 160,
                top: ($(window).height() - 160) * 0.5,      //居中
                left: ($(window).width() - 700) * 0.5,
                closed: true,
                cache: false,
                modal: true,
                buttons: '#dlg-buttons'
            });
        }
    </script>
    <script>
        //表单验证和提交
        $(function () {
            $('#form').validate({
                rules: {
                    PurchaseNum: {
                        required: true
                    }
                },
                messages: {
                    PurchaseNum: "采购数量不能为空！"
                },
                errorLabelContainer: '#errdiv>ul',
                wrapper: 'li',
                submitHandler: function (form) {
                    var postData = GetWebControls("#form");
                    getAjax("/PSS_PurchasePlanDetail/AcceptClick",
                        postData, function (data) {
                            if (data) {
                                $.messager.alert('提示', '添加药品成功!');
                                $('#dd').dialog('close');
                                $("#grid").datagrid("reload");
                                return true;
                            }
                            else {
                                $.messager.alert('提示', '操作失败!');
                                return false;
                            }
                        });
                },
                invalidHandler: function (form, validator) {  //不通过回调
                    return false;
                }
            });
        });
    </script>
    <style>
        .dis {
            display: none;
        }

        .tb-col-120 {
            width: 120px;
        }

        .tb-col-80 {
            width: 80px;
        }

        #errdiv {
            margin-left: 5px;
        }
    </style>
</head>
<body class="easyui-layout" id="body">
    <div id="left_part" data-options="region:'west'" style="float:left;width:340px;">
        <div id="phaselect">
            <div style="position:fixed;width:340px;height:100%;">
                <table id="phagrid"></table>
            </div>
            <div id="phagrid_tb" style="padding:3px">
                <span>拼音码:</span>
                <input id="phagrid_dir" style="border:1px solid #ccc">
                <a href="#" class="easyui-linkbutton" plain="true" onclick="InitPhaDialoggrid()">查找</a>
            </div>
        </div>
    </div>
    <div data-options="region:'center'" style="float:left">
        <div data-options="region:'north'" style="height:25%;">
            <h2 style="text-align:center;margin-top:20px;">中心医院药品采购单</h2>
            <div>
                <p style="font-weight:900;color:red;font-size:medium;text-align:right;margin-right:20%">
                    No.<span id="PurchaseNo">@Model.PurchaseNo</span>
                </p>
                <div style="margin:10px 0 10px 20px ">
                    <div style="display:inline-block;margin-right:10px">采购日期：<span id="PurchaseDate" style="color:red">@Model.PurchaseDate.Split(' ')[0]</span></div>
                    <div style="display:inline-block;margin-right:10px">操作工号：<span id="OperateNo" style="color:red">@Model.OperateNo</span></div>
                    <div style="display:inline-block;margin-right:10px">操作日期：<span id="OperateDate" style="color:red">@Model.OperateDate.Split(' ')[0]</span></div>
                    <div style="display:inline-block;margin-right:10px">采购状态：<span id="status" style="color:red"></span></div>
                </div>
                <div style="margin:0 0 10px 20px">
                    <p id="OperateNo">备注：@Model.Remark</p>
                </div>
            </div>
        </div>
        <div data-options="region:'south'" style="height:70%">
            <table id="grid"></table>
            <input id="del_id" type="hidden" name="del_id" value=" " />
        </div>
    </div>

    <div id="dd" class="easyui-dialog">
        <form id="form" name="form" method="post">
            <input type="hidden" id="PurchaseNo" name="PurchaseNo" value="@Model.PurchaseNo" />
            <input type="hidden" id="PhaCode" name="PhaCode" value=" " />
            <input type="hidden" id="OrginID" name="OrginID" value=" " />
            <table style="margin:8px">
                <tr>
                    <td>药品名:</td>
                    <td><input type="text" id="PhaName" name="PhaName" class="tb-col-120" value=" " disabled="disabled" /></td>

                    <td>规格:</td>
                    <td><input type="text" id="Spec" name="Spec" class="tb-col-80" value=" " disabled="disabled" /></td>

                    <td>单位:</td>
                    <td><input type="text" id="Unit" name="Unit" class="tb-col-80" value="" disabled="disabled" /></td>

                    <td>产地:</td>
                    <td><input type="text" id="OrginName" name="OrginName" class="tb-col-80" value=" " disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>进货价格:</td>
                    <td><input type="text" id="InWarehousePrice" name="InWarehousePrice" class="tb-col-120" value=" " disabled="disabled" /></td>
                    <td>采购数量:</td>
                    <td><input type="text" id="PurchaseNum" name="PurchaseNum" class="tb-col-80" value="" /></td>
                    <td>生产厂家:</td>
                    <td colspan="3"><input type="text" id="CompanyName" name="CompanyName" value=" " disabled="disabled" /></td>
                </tr>
            </table>
            <div class="errdiv" id="errdiv">
                <ul></ul>
            </div>
            <div id="dlg-buttons">
                <a id="ok" href="#" class="easyui-linkbutton" iconcls="icon-ok">确定</a>
                <a id="cancel" href="#" class="easyui-linkbutton" iconcls="icon-cancel">取消</a>
            </div>

        </form>
    </div>
</body>
</html>
